/*
*
* Option (SELECT) - jQuery plugin 1.0
* http://www.jquery.com
*
* Copyright (c) 2010 Peter Sirka / Web Site Design, s.r.o. http://www.wsd-europe.com
* http://plugins.jquery.com/project/Option
*
* GPL License
* Date: 2010-10-15
*
*/

(function(c){c.fn.optionCopyTo=function(b,h){function a(d,e){for(var i=0;i<d.length;i++)e(d[i],i)}var f=c(this).get(0);if(!(typeof f.type=="undefined"||f.type.toString().toLowerCase()!="select-one")){b=c(b).toArray();a(b,function(d){var e=c(d).get(0);if(!(typeof e.type=="undefined"||e.type.toString().toLowerCase()!="select-one")){if(!h)for(;e.firstChild;)e.removeChild(e.firstChild);var i=null,k=null;a(f.options,function(g){if(g.parentNode!=f)if(i!=g.parentNode){k=document.createElement("OPTGROUP");
k.setAttribute("label",g.parentNode.label);e.appendChild(k);i=g.parentNode}var j=document.createElement("OPTION");j.value=g.value;j.text=g.text;j.innerHTML=g.text;g.parentNode!=f?k.appendChild(j):e.options.add(j)})}});return this}};c.fn.optionClear=function(){this.each(function(){for(;this.firstChild;)this.removeChild(this.firstChild)});return this};c.fn.optionSelect=function(b,h){this.each(function(){for(var a=c(this).get(0),f=0;f<a.options.length;f++){var d=a.options[f];if(h){if(d.text==b){d.selected=
true;return this}}else if(d.value==b){d.selected=true;return this}}});return this};c.fn.optionValue=function(b,h){var a=[];this.each(function(){a[a.length]=this.selectedIndex==-1?h:b?this[this.selectedIndex].text:this[this.selectedIndex].value});return a.length==1?a[0]:a};c.fn.optionAdd=function(b,h){this.each(function(){var a=document.createElement("OPTION");a.value=h;a.text=b;a.innerHTML=b;this.options.add(a)});return this}})(jQuery); 